//
//  AnswerDetailAllCommentsVC.m
//  OnionHome
//
//  Created by fengjie on 2019/9/20.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "AnswerDetailAllCommentsVC.h"
#import "AnswerDetailCommentsCell.h"

@interface AnswerDetailAllCommentsVC ()<UITableViewDelegate,UITableViewDataSource>
/**底部输入框视图*/
@property (nonatomic,strong)CommentsTwoBottomView*bottomView;
/**键盘上面评论输入框*/
@property (nonatomic,strong)PubulicInputToolbar*inputToolbar;

/**listView*/
@property (nonatomic,strong)UITableView*listView;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSoure;

@end

@implementation AnswerDetailAllCommentsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigation];
    [self createUI];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setIQKeyboardManagerEnable:NO];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    [self setIQKeyboardManagerEnable:YES];
}
-(void)createUI{
    [self.view addSubview:self.bottomView];
    [self.view addSubview:self.listView];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    [self.bottomView.textFiledBgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.bottom.mas_equalTo(0);
     make.right.mas_equalTo(self.bottomView.dianzanBtn.mas_left).offset(-16);
    }];
    
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.bottom.mas_equalTo(self.bottomView.mas_top);
    }];
    [self.view addSubview:self.inputToolbar];

}
-(void)setNavigation{
    [self addNavigationItemWithImageNames:@[@"X"] isLeft:YES target:self action:@selector(backBtnClicked) tags:nil];
    self.title = @"24条回复";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName :UIColorFromRGB(0x009966), NSFontAttributeName : SYSTEMFONT(19)}];
}
-(void)backBtnClicked{
    [super backBtnClicked];
    [PresentationObject sharedPresentationObject].alpha_bgView = 0;
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    DLogFunc;
    [self.view endEditing:YES];
}

#pragma mark ---UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AnswerDetailCommentsOneCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AnswerDetailCommentsOneCell class])];
    if (indexPath.section == 0) {
        cell.reportBtn.hidden = NO;
        cell.authorLb.hidden = NO;
    }else{
        cell.reportBtn.hidden = YES;
        cell.authorLb.hidden = YES;
    }
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * view = UIView.new;
    if (section == 1) {
        UIView * aview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 30)];
        aview.backgroundColor = KWhiteColor;
        UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, KScreenWidth, 30)];
        label.textColor = UIColorFromRGB(0x273323);
        label.font = SYSTEMFONT(14);
        label.text = @"全部评论";
        
        [aview addSubview:label];
        
        
        return aview;
    }
    return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return UIView.new;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 8.0f;
    }
    return 0.01f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 30.0f;
    }
    return 0.01f;
}

-(PubulicInputToolbar*)inputToolbar{
    if(!_inputToolbar){
        _inputToolbar=[[PubulicInputToolbar alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view.frame), KScreenWidth, 50)];
        _inputToolbar.textViewMaxLine = 3;
        _inputToolbar.fontSize = 18;
        _inputToolbar.placeholder = @"写回复...";
        if (!self.isFullScreen) {
            CGRect subViewFrame = [PresentationObject sharedPresentationObject].subViewFrame;
            _inputToolbar.bomttomView_y = subViewFrame.origin.y - 20;
        }
        kWeakSelf(weakSelf);
        [_inputToolbar inputToolbarSendText:^(NSString * _Nonnull text) {
            // 清空输入框文字
            [weakSelf.inputToolbar bounceToolbar];
        }];
    }
    return _inputToolbar;
}
-(CommentsTwoBottomView*)bottomView{
    if(!_bottomView){
        _bottomView=[[CommentsTwoBottomView alloc] initWithFrame:CGRectZero];
        _bottomView.textField.placeholder = @"写回复...";
        kWeakSelf(weakSelf);
        [_bottomView settextFieldEnabled:^{
            [weakSelf.inputToolbar popToolbar];
        }];
    }
    return _bottomView;
}
-(NSMutableArray *)dataSoure{
    if (!_dataSoure) {
        _dataSoure =[[NSMutableArray alloc] init];
    }
    return _dataSoure;
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        [_listView registerClass:[AnswerDetailCommentsOneCell class] forCellReuseIdentifier:NSStringFromClass([AnswerDetailCommentsOneCell class])];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

    }
    return _listView;
}
@end
